package com.wx.auth.servlet;

import com.wx.auth.utils.AuthUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;

/**
 * @Author: lijunwei
 * @Time: 2018/6/24 0:07
 */
@WebServlet("/wxLogin")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        String backUrl = "http://iekuang16.s3.luyouxia.net:20675/wxCallBack";
        String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+ AuthUtil.APPID
                + "&redirect_uri="+ URLEncoder.encode(backUrl)
                + "&response_type=code"
                + "&scope=snsapi_userinfo"
                + "&state=STATE#wechat_redirect";
        //---url----001----https://open.weixin.qq.com/connect/oauth2/authorize?
        // appid=wx73f59af1123b83bb&redirect_uri=http%3A%2F%2Fiekuang16.s3.luyouxia.net%3A20675%2FwxCallBack
        // &response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect
        System.out.println("---url----001----"+url);
        resp.sendRedirect(url);
    }
}